#include<iostream>
using namespace std;
#define MAXSIZE 100
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
int m; //m为操作次数
typedef struct
{ ElemType *elem;
  int length;
}SqList;//顺序表

void CreateList(SqList &L, int n){
    L.elem = new ElemType[MAXSIZE];
    L.length = n;
    for(int i = 0; i < n; i++){
        cin >> L.elem[i];
    }
}

Status GetElem(SqList L, int i, ElemType &e){
    if(i < 1 || i > L.length) return ERROR;
    e = L.elem[i-1];
    return OK;
}

bool LocateElem(SqList L, ElemType e){
    for(int i = 0; i < L.length; ++i){
        if(L.elem[i] == e) return true;
    }
    return false;
}
void ListInsert(SqList &L, ElemType e){
    if(L.length < MAXSIZE){
        L.elem[L.length++] = e;
    }
}
void MergeList(SqList &LA, SqList LB){
    for(int i = 0; i < LB.length; ++i){
        ElemType b = LB.elem[i];
        if(!LocateElem(LA,b)){
            ListInsert(LA,b);
        }
    }
}

void Out_list(SqList L){//输出顺序表
    for(int i=0; i<=L.length-1;i++)
        cout <<L.elem[i]<<' ';
    cout<<endl;
}

int main() {
    SqList LA,LB;
    int j,k;
    cin >> m;     //m次操作
    while(m --) {
        char op;
        cin >> op;
        switch(op){
            case 'A'://创建顺序表LA
                cin>>j;
                CreateList(LA, j);
                Out_list(LA);
                break;
            case 'B'://创建顺序表LB
                cin>>k;
                CreateList(LB, k);
                Out_list(LB);
                break;
            case 'M'://合并
                MergeList(LA, LB);
                Out_list(LA);
                break;
        }
    }
    return 0;
}
